package com.health.modules.user.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.health.common.exception.HealthException;
import com.health.domain.dao.UserDao;
import com.health.domain.model.User;
import com.health.framework.dao.BaseDao;
import com.health.framework.service.BaseService;
import com.health.modules.user.action.vo.UserVo;

@Service
@SuppressWarnings({"rawtypes", "unchecked"})
public class UserService extends BaseService<User, Integer> {

    @Autowired
    private UserDao userDao;
    
    @Override
    protected BaseDao getEntityDao() {
        return userDao;
    }

    public User login(final UserVo userVo) throws HealthException {
        User user = userDao.getByUsername(userVo.getUsername());
        if (null != user && user.getPassword().equals(userVo.getPassword())) {
            user.setLastLoginTime(new Date());
            userDao.update(user);
            
            return user;
        } else {
            return null;
        }
    }
    
}
